package com.xiyu.service.repository.bed.room;

import com.xiyu.service.model.bed.room.RoomType;
import com.xiyu.service.model.bed.room.RoomTypeTable;
import com.xiyu.service.vo.bed.bedInfo.BedInfoRoomTypeQueryInput;
import org.babyfish.jimmer.spring.repository.JRepository;
import org.babyfish.jimmer.Page;
import org.springframework.util.StringUtils;

import java.util.Optional;

public interface RoomTypeRepository extends JRepository<RoomType, Long> {
    RoomTypeTable roomTypeTable = RoomTypeTable.$;

    default Page<RoomType> pageQuery(BedInfoRoomTypeQueryInput inputVO){
        return sql().createQuery(roomTypeTable)
                .whereIf(StringUtils.hasText(inputVO.getTypeName()), () ->  roomTypeTable.typeName().like(inputVO.getTypeName()))
                .orderBy(roomTypeTable.id().desc())
                .select(roomTypeTable)
                .fetchPage(inputVO.getPageNo() - 1, inputVO.getPageSize());
    }

    Optional<RoomType> findFirstByTypeName(String typeName);

    Optional<RoomType> findFirstByTypeNameAndIdNot(String typeName, Long id);

}